﻿Public Class cPeriodos
    Dim lDrPeriodo As dsGlobal.GLO_PERIODOSRow
    Private Sub GetPeriodo(ByVal Periodo As String)
        Try
            Dim daPeriodo As New dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
            Dim dtPer As New dsGlobal.GLO_PERIODOSDataTable
            daPeriodo.FillByIdPeriodo(dtPer, Periodo)
            If dtPer.Rows.Count > 0 Then
                lDrPeriodo = dtPer.Rows(0)
            Else
                Throw New Exception("Periodo no existe, favor verificar e intentar de nuevo")
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub
    Public Sub New(ByVal IDPERIODO As String)
        GetPeriodo(IDPERIODO)
    End Sub
    Public Sub New(ByVal Fecha As Date)
        Try
            Dim daPeriodo As New dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
            Dim dtPer As dsGlobal.GLO_PERIODOSDataTable = daPeriodo.GetDataByFecha(Fecha)
            If dtPer.Rows.Count > 0 Then
                lDrPeriodo = dtPer.Rows(0)
            Else
                Throw New Exception("Periodo no existe, favor verificar e intentar de nuevo")
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub
    Public Sub New()
        Try
            Dim daPeriodo As New dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
            Dim dtPer As dsGlobal.GLO_PERIODOSDataTable = daPeriodo.GetDataByEstado(2)
            If dtPer.Rows.Count > 0 Then
                lDrPeriodo = dtPer.Rows(0)
            Else
                Throw New Exception("Periodo no existe, favor verificar e intentar de nuevo")
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub
    Public Sub AfterPeriodo()
        Try
            Dim Año As Int16 = lDrPeriodo.IDPERIODO.Substring(0, 4)
            Dim Mes As Int16 = lDrPeriodo.IDPERIODO.Substring(4, 2)
            If Mes = 1 Then
                Mes = 12
                Año -= 1
            Else
                Mes -= 1
            End If
            GetPeriodo(Año.ToString & Mes.ToString.PadLeft(2, "0"))
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub NextPeriodo()
        Try
            Dim Año As Int16 = lDrPeriodo.IDPERIODO.Substring(0, 4)
            Dim Mes As Int16 = lDrPeriodo.IDPERIODO.Substring(4, 2)
            If Mes = 12 Then
                Mes = 1
                Año += 1
            Else
                Mes += 1
            End If
            GetPeriodo(Año.ToString & Mes.ToString.PadLeft(2, "0"))
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public ReadOnly Property IDPERIODO() As String
        Get
            Return lDrPeriodo.IDPERIODO
        End Get
    End Property
    Public ReadOnly Property DESCRIPCION() As String
        Get
            Return lDrPeriodo.DESCRIPCION
        End Get
    End Property
    Public ReadOnly Property DESDEF() As DateTime
        Get
            Return lDrPeriodo.DESDEF
        End Get
    End Property
    Public ReadOnly Property HASTAF() As DateTime
        Get
            Return lDrPeriodo.HASTAF
        End Get
    End Property
    Public ReadOnly Property ESTADO() As Int16
        Get
            Return lDrPeriodo.ESTADO
        End Get
    End Property

End Class
